home *** CD-ROM | disk | FTP | other *** search
- /*
- * #include <legal/bs.h>
- >
- > Copyright (c) 1989 Washington University in Saint Louis, Missouri and
- > Chris Myers. All rights reserved.
- >
- > Permission is hereby granted to copy, reproduce, redistribute or
- > otherwise use this software as long as: (1) there is no monetary
- > profit gained specifically from the use or reproduction of this
- > software, (2) it is not sold, rented, traded, or otherwise marketed,
- > (3) the above copyright notice and this paragraph is included
- > prominently in any copy made, and (4) that the name of the University
- > is not used to endorse or promote products derived from this software
- > without the specific prior written permission of the University.
- > THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- > IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- > WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- >
- */
-
- #include "defs.h"
- char *progname = "newsxd";
-
- /*************************************************************************/
- /* FUNCTION : main */
- /* PURPOSE : */
- /* ARGUMENTS : argc and argv passed in by calling program */
- /*************************************************************************/
-
- void
- main(argc, argv, envp)
- int argc;
- char *argv[], *envp[];
-
- {
- int loop,
- ltime,
- clock,
- pid,
- sleeptime;
-
- FILE *pidout;
-
- struct tm *curtime;
-
- debug = 0;
- DEBUG = 0;
- newsxdebug = 0;
-
- (void) strcpy(configfile, default_configfile);
- (void) strcpy(statusfile, default_statusfile);
- (void) strcpy(pidfile, default_pidfile);
- #ifdef FAKESYSLOG
- (void) strcpy(fakelogfile, FAKESYSLOG);
- #endif FAKESYSLOG
-
- for (loop = 0; loop < argc; loop++) {
-
- if (strcmp(argv[loop], "-v") == 0) {
- (void) fprintf(stderr, "newsxd version %1.1f", VERSION);
- #if PATCHLEVEL > 0
- (void) fprintf(stderr, "-%d", PATCHLEVEL);
- #endif
- (void) fprintf(stderr, ", written by Chris Myers <chris@wugate.wustl.edu>\n");
- #ifdef SYSLOG
- (void) fprintf(stderr, "Logging to syslog\n");
- #endif
- #ifdef FAKESYSLOG
- (void) fprintf(stderr, "Logging to %s\n", fakelogfile);
- #endif
- exit(0);
- }
- if (strcmp(argv[loop], "-debug") == 0) debug++;
- if (strcmp(argv[loop], "-DEBUG") == 0) { DEBUG++; debug++; }
- if (strcmp(argv[loop], "-newsxdebug") == 0) newsxdebug++;
- if ((strcmp(argv[loop], "-c") == 0) && (loop < argc - 1))
- (void) strcpy(configfile, argv[++loop]);
- if ((strcmp(argv[loop], "-pid") == 0) && (loop < argc - 1))
- (void) strcpy(pidfile, argv[++loop]);
- if ((strcmp(argv[loop], "-status") == 0) && (loop < argc - 1))
- (void) strcpy(statusfile, argv[++loop]);
- #ifdef FAKESYSLOG
- if ((strcmp(argv[loop], "-log") == 0) && (loop < argc - 1))
- (void) strcpy(fakelogfile, argv[++loop]);
- #endif
-
- }
-
- (void) signal(SIGCHLD, xmit_done);
- (void) signal(SIGHUP, read_config);
- (void) signal(SIGQUIT, dump_config);
- (void) signal(SIGTERM, kill_children);
- (void) signal(SIGUSR1, debug_on);
- (void) signal(SIGUSR2, debug_off);
- (void) signal(SIGIO, idle);
- (void) signal(SIGIOT, reset);
- (void) signal(SIGTRAP, dump_info);
-
- (void) setuid(geteuid());
- (void) setgid(getegid());
-
- if (!debug) daemon_start();
-
- #ifdef SYSLOG
- # ifdef LOG_LOCAL7
- openlog("newsxd", LOG_PID, SYSLOG);
- # else
- openlog("newsxd", LOG_PID);
- # endif
- #endif
-
- pidout = fopen(pidfile, "r");
- if (pidout != (FILE *) NULL) {
- (void) fscanf(pidout, "%d", &pid);
- (void) fclose(pidout);
- if (kill(pid, 0) == 0) {
- logerr("duplicate invocation of newsxd -- aborting\n");
- (void) exit(1);
- }
- }
-
- log(LOG_INFO, "starting\n");
-
- for (loop = 0; loop < MAXXMITTERS; loop++) {
- pidlist[loop] = 0;
- pidmap[loop] = (struct host *) NULL;
- }
-
- read_config(0);
-
- if (debug) dump_config();
-
- pidout = fopen(pidfile, "w");
-
- if (pidout != (FILE *) NULL) {
- (void) fprintf(pidout, "%d\n", getpid());
- (void) fflush(pidout);
- (void) fclose(pidout);
- }
-
- while (1) {
- if (!daemon_idle) run_queue();
-
- xmit_done(0);
-
- (void) time(&clock);
- curtime = localtime(&clock);
- ltime = curtime->tm_sec + curtime->tm_min * 60 + curtime->tm_hour * 3600;
-
- sleeptime = queueinterval - (ltime % queueinterval);
- if (sleeptime == 0) sleeptime++;
-
- dprintf("%d:sleeping for %d seconds\n", ltime, sleeptime);
-
- (void) sleep((unsigned) sleeptime);
-
- }
- }
-